package com.erebus.utils;


import com.erebus.model.dto.Constant;

// 卜卦算法
public class DivinationAlgorithm {

    private String[] list = {Constant.TEXT0, Constant.TEXT1, Constant.TEXT2, Constant.TEXT3, Constant.TEXT4, Constant.TEXT5, Constant.TEXT6, Constant.TEXT7, Constant.TEXT8, Constant.TEXT9, Constant.TEXT10, Constant.TEXT11, Constant.TEXT12, Constant.TEXT13, Constant.TEXT14, Constant.TEXT15,
            Constant.TEXT16, Constant.TEXT17, Constant.TEXT18, Constant.TEXT19, Constant.TEXT20, Constant.TEXT21, Constant.TEXT22, Constant.TEXT23, Constant.TEXT24, Constant.TEXT25, Constant.TEXT26, Constant.TEXT27, Constant.TEXT28, Constant.TEXT29, Constant.TEXT30, Constant.TEXT31, Constant.TEXT32, Constant.TEXT33, Constant.TEXT34, Constant.TEXT35, Constant.TEXT36, Constant.TEXT37, Constant.TEXT38, Constant.TEXT39, Constant.TEXT40, Constant.TEXT41, Constant.TEXT42, Constant.TEXT43, Constant.TEXT44, Constant.TEXT45, Constant.TEXT46, Constant.TEXT47, Constant.TEXT48, Constant.TEXT49, Constant.TEXT50, Constant.TEXT51, Constant.TEXT52, Constant.TEXT53, Constant.TEXT54, Constant.TEXT55, Constant.TEXT56,
            Constant.TEXT57, Constant.TEXT58, Constant.TEXT59, Constant.TEXT60, Constant.TEXT61, Constant.TEXT62, Constant.TEXT63};

    public DivinationAlgorithm() {
    }

    // 将二进制字符串转换为十进制整数   Index
    public int parseBinaryStringToInt(String binaryString) {
        try {
            // 将二进制字符串转换为十进制整数
            int decimalValue = Integer.parseInt(binaryString, 2);
            return decimalValue;
        } catch (NumberFormatException e) {
            System.out.println("二进制字符串格式无效.");
            return -1;
        }
    }

    public String toBinaryString(int[] list) {

        if (list == null || list.length == 0) {
            return "";
        }
        // 使用StringBuilder来构建结果字符串，因为它的性能在字符串拼接时更好
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < list.length; i++) {
            if(list[i] % 2 == 0) {
                sb.append("0");
            }
            else {
                sb.append(1);
            }
        }

        return sb.toString();

    }

    public String getDivinationResult(int index) { // int返回对应的卦象
        String s = list[index];

        return s;
    }


}